param(
	[string]$src,
	[string]$dest,
	[string]$username,
	[string]$password 
)

Write-Host "src: $src"
Write-Host "dest: $dest"
Write-Host "username: $username"
Write-Host "password: $password"
if(!$dest.Contains("\\") -or !$dest.Contains('$')) {
	throw 'dest must be in the format \\[server]\[drive]$\'
}
$mapdrive = $dest.SubString(0, $dest.IndexOf('$')+1) #assuming single letter drives, cant have a trailing "\"
$path = $dest.SubString(0, $dest.LastIndexOf('\')+1)
Write-Host "mapdrive: $mapdrive"
Write-Host "path: $path"
Write-Host "mapping drive"
& "net" "use" "$mapdrive" "$password" "/USER:$username"
if(!(Test-Path $path)) {
	& "mkdir" "$path"
}
Write-Host "copying"
& "copy" $src "$dest"
Write-Host "removing drive mapping"
& "net" "use" $mapdrive "/delete"
